home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / comm / misc / DigiCam.lha / src / debughelp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-15  |  821 b   |  37 lines

  1. /* debughelp.c (c) 1999 by Volker Remuß, remuss@cs.tu-berlin.de */
  2.  
  3. #include <stdio.h>
  4.  
  5. #define COLUMNS 12
  6.  
  7. void hexdump (unsigned char *buf, int cnt)
  8. /* output of complete buffer in hex and as far as possible as human readable */
  9. {
  10.   int i, nochncnt=0;
  11.   unsigned char nochnbuf[COLUMNS*4+10];
  12.  
  13.   for (i=0; i < cnt; i++)
  14.   {
  15.     printf("%2hx ", buf[i]);
  16.  
  17.     if ((buf[i] >= ' ') && (buf[i] <='~'))     // readable character? if not write a . instead
  18.       nochnbuf[nochncnt++] = buf[i];
  19.     else
  20.       nochnbuf[nochncnt++] = '.';
  21.  
  22.     if ((nochncnt) > (COLUMNS - 1))
  23.     {
  24.       nochnbuf[nochncnt] = 0;
  25.       printf("     %s\n", nochnbuf);
  26.       nochncnt = 0;
  27.     }
  28.   }
  29.  
  30.   if (nochncnt)
  31.   {
  32.     nochnbuf[nochncnt] = '\0';
  33.     for (i=(COLUMNS-nochncnt); i > 0; i--) printf("   ");
  34.     printf("     %s\n", nochnbuf);
  35.   }
  36. }
  37.